﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Xml;
using Meqs.Entity.Views;

namespace Meqs.Logic.Implement.MsSql
{
    public class EvalSheetsLogic : AbEvalSheetsLogic
    {
        /// <summary>
        /// 获取教师评估项树的xml文件内容
        /// </summary>
        /// <param name="teachID"></param>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <param name="schoolMark"></param>
        /// <returns></returns>
        public override string GetSheetItemXmlStr(int teachID, string startDate, string endDate, string schoolMark)
        {
            using (SqlConnection conn = new SqlConnection(ConnectionString))
            {
                conn.Open();
                SqlCommand cmd = conn.CreateCommand();
                cmd.CommandText = schoolMark + ".GENERATORXMLTREE";
                cmd.CommandType = CommandType.StoredProcedure;

                SqlParameter teachIDPara = new SqlParameter("@teachID", SqlDbType.Int);
                teachIDPara.Value = teachID;
                cmd.Parameters.Add(teachIDPara);

                SqlParameter startDatePara = new SqlParameter("@startDate", SqlDbType.VarChar);
                startDatePara.Value = startDate;
                cmd.Parameters.Add(startDatePara);

                SqlParameter endDatePara = new SqlParameter("@endDate", SqlDbType.VarChar);
                endDatePara.Value = endDate;
                cmd.Parameters.Add(endDatePara);

                SqlParameter returnValuePara = new SqlParameter("@returnXmlType", SqlDbType.VarChar);
                returnValuePara.Direction = ParameterDirection.Output;
                returnValuePara.Size = 32767;
                cmd.Parameters.Add(returnValuePara);

                cmd.ExecuteNonQuery();

                conn.Dispose();

                return returnValuePara.Value.ToString();
            }
        }
        private int _globalId = 1;
        /// <summary>
        /// 获取教师评估项树的xml文件内容
        /// </summary>
        /// <param name="teachID"></param>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <param name="schoolMark"></param>
        /// <returns></returns>
        public override object[] GetSheetItemXmlStr1(int teachID, string startDate, string endDate, string schoolMark)
        {
            _globalId = 1;
            XmlDocument doc = new XmlDocument();
            DateTime start = DateTime.Parse(startDate + "-01");
            DateTime end = DateTime.Parse(endDate + "-01");
            end = end.AddMonths(1).AddMilliseconds(-1);

            using (SqlConnection conn = new SqlConnection(ConnectionString))
            {
                conn.Open();
                SqlCommand cmd = conn.CreateCommand();
                cmd.CommandText = string.Format("select taskidlist from {0}.EVALSETTINGS where destid = {1}", schoolMark, teachID);
                cmd.CommandType = CommandType.Text;
                object taskids = cmd.ExecuteScalar();
                if (taskids == null || taskids.ToString() == "") return new object[] { 0, "" };
                string strtaskids = taskids.ToString();
                strtaskids.TrimEnd(',');

                string sql = @"
                    select cast(datepart(year, es.evaldate) as varchar(4)) + '-' + 
                    cast(datepart(month, es.evaldate) as varchar(2)) EvalDateStr
                    from {0}.EVALSHEETS es
                    left join {0}.TEMPLATES tp on es.templateid = tp.rid
                    where tp.evalitemid in ({1}) and es.studenteval <> 1
                    and evaldate between '{2}' and '{3}'
                    group by cast(datepart(year, es.evaldate) as varchar(4)) + '-' + cast(datepart(month, es.evaldate) as varchar(2))
                    order by cast(
	                    cast(datepart(year, es.evaldate) as varchar(4)) + '-' + 
	                    cast(datepart(month, es.evaldate) as varchar(2)) + '-01'
                    as datetime) desc";
                sql = string.Format(sql, schoolMark, taskids, start.ToString("yyyy-MM-dd"), end.ToString("yyyy-MM-dd"));
                cmd.CommandText = sql;
                cmd.CommandType = CommandType.Text;
                DataTable dt = new DataTable();
                SqlDataAdapter ad = new SqlDataAdapter(cmd);
                ad.Fill(dt);


                doc.CreateXmlDeclaration("1.0", "utf-8", null);
                XmlElement root = doc.CreateElement("tree");
                root.SetAttribute("id", "0");
                doc.AppendChild(root);

                foreach (DataRow row in dt.Rows)
                {
                    string dateStr = row[0].ToString();

                    XmlElement dateNode = doc.CreateElement("item");
                    dateNode.SetAttribute("id", _globalId.ToString());
                    dateNode.SetAttribute("text", dateStr);
                    dateNode.SetAttribute("im0", "orgClose.png");
                    dateNode.SetAttribute("im1", "organization.png");
                    dateNode.SetAttribute("im2", "orgClose.png");

                    #region 新增用户自定义节点

                    XmlElement userdataId = doc.CreateElement("userdata");
                    userdataId.SetAttribute("name", "id");
                    userdataId.InnerText = "-1";
                    dateNode.AppendChild(userdataId);

                    XmlElement userdataNodeType = doc.CreateElement("userdata");
                    userdataNodeType.SetAttribute("name", "NodeType");
                    userdataNodeType.InnerText = "Date";
                    dateNode.AppendChild(userdataNodeType);

                    #endregion
                    root.AppendChild(dateNode);
                    _globalId++;

                    GeneratorEvalItemsNode(conn, dateStr, strtaskids, schoolMark, dateNode, doc);
                }
            }

            return new object[] { _globalId, doc.InnerXml };
        }

        /// <summary>
        /// 生成EvalItems节点
        /// </summary>
        /// <param name="conn"></param>
        /// <param name="dateStr"></param>
        /// <param name="strtaskids"></param>
        /// <param name="schoolMark"></param>
        /// <param name="dateNode"></param>
        /// <param name="doc"></param>
        /// <returns></returns>
        private void GeneratorEvalItemsNode(SqlConnection conn, string dateStr, string strtaskids, string schoolMark, XmlNode dateNode, XmlDocument doc)
        {
            if (conn.State != ConnectionState.Open) conn.Open();
            string sql = @"
        select ei.rid, ei.evalname from {0}.EvalSheets es
        left join {0}.TEMPLATES tp on es.templateid = tp.rid
        left join {0}.EvalItems ei on tp.evalitemid = ei.rid
        where cast(cast(datepart(year, es.evaldate) as varchar(4)) + '-' + cast(datepart(month, es.evaldate) as varchar(2)) + '-01' as datetime) 
        = cast('{1}-01' as datetime)
        and ei.rid in ({2}) and es.studenteval <> 1
        group by ei.rid, ei.evalname";
            sql = string.Format(sql, schoolMark, dateStr, strtaskids);
            DataTable dt = new DataTable();
            SqlCommand cmd = conn.CreateCommand();
            cmd.CommandText = sql;
            cmd.CommandType = CommandType.Text;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(dt);

            foreach (DataRow row in dt.Rows)
            {
                int eiId = Convert.ToInt32(row[0]);
                string eiName = Convert.ToString(row[1]);
                XmlElement evalItemNode = doc.CreateElement("item");

                evalItemNode.SetAttribute("id", _globalId.ToString());
                evalItemNode.SetAttribute("text", HttpContext.Current.Server.HtmlDecode(eiName.Replace("'", "\\'").Replace(";", "\\;")));
                evalItemNode.SetAttribute("im0", "orgClose.png");
                evalItemNode.SetAttribute("im1", "organization.png");
                evalItemNode.SetAttribute("im2", "orgClose.png");

                #region 新增用户自定义节点

                XmlElement userdataId = doc.CreateElement("userdata");
                userdataId.SetAttribute("name", "id");
                userdataId.InnerText = eiId.ToString();
                evalItemNode.AppendChild(userdataId);

                XmlElement userdataNodeType = doc.CreateElement("userdata");
                userdataNodeType.SetAttribute("name", "NodeType");
                userdataNodeType.InnerText = "EvalItems";
                evalItemNode.AppendChild(userdataNodeType);

                #endregion

                dateNode.AppendChild(evalItemNode);
                _globalId++;
                GeneratorEvalSheetsNode(conn, eiId, schoolMark, dateStr, evalItemNode, doc);
            }
        }


        /// <summary>
        /// 生成EvalSheets节点
        /// </summary>
        /// <param name="conn"></param>
        /// <param name="eiId"></param>
        /// <param name="schoolMark"></param>
        /// <param name="evalItemNode"></param>
        /// <param name="doc"></param>
        /// <returns></returns>
        private void GeneratorEvalSheetsNode(SqlConnection conn, int eiId, string schoolMark, string dateStr, XmlNode evalItemNode, XmlDocument doc)
        {
            if (conn.State != ConnectionState.Open) conn.Open();
            string sql = @"
        select es.rid, es.sheetname from {0}.EvalSheets es
        left join {0}.TEMPLATES tp on es.templateid = tp.rid
        left join {0}.EvalItems ei on tp.evalitemid = ei.rid
        where ei.rid = {1} and es.studenteval <> 1 
        and cast(cast(datepart(year, es.evaldate) as varchar(4)) + '-' + cast(datepart(month, es.evaldate) as varchar(2)) + '-01' as datetime) 
        = cast('{2}-01' as datetime)";
            sql = string.Format(sql, schoolMark, eiId, dateStr);
            DataTable dt = new DataTable();
            SqlCommand cmd = conn.CreateCommand();
            cmd.CommandText = sql;
            cmd.CommandType = CommandType.Text;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(dt);


            foreach (DataRow row in dt.Rows)
            {
                int esId = Convert.ToInt32(row[0]);
                string esName = Convert.ToString(row[1]);
                XmlElement evalSheetNode = doc.CreateElement("item");

                evalSheetNode.SetAttribute("id", _globalId.ToString());
                evalSheetNode.SetAttribute("text", HttpContext.Current.Server.HtmlDecode(esName.Replace("'", "\\'").Replace(";", "\\;")));
                evalSheetNode.SetAttribute("im0", "st.png");
                evalSheetNode.SetAttribute("im1", "st.png");
                evalSheetNode.SetAttribute("im2", "st.png");

                #region 新增用户自定义节点

                XmlElement userdataId = doc.CreateElement("userdata");
                userdataId.SetAttribute("name", "id");
                userdataId.InnerText = esId.ToString();
                evalSheetNode.AppendChild(userdataId);

                XmlElement userdataNodeType = doc.CreateElement("userdata");
                userdataNodeType.SetAttribute("name", "NodeType");
                userdataNodeType.InnerText = "EvalSheets";
                evalSheetNode.AppendChild(userdataNodeType);

                #endregion

                _globalId++;
                evalItemNode.AppendChild(evalSheetNode);
            }
        }

        /// <summary>
        /// 获取时间范围内所有检查单所属的检查项
        /// </summary>
        /// <param name="begin"></param>
        /// <param name="end"></param>
        /// <param name="schoolMark"></param>
        /// <param name="groupType"></param>
        /// <param name="groupID"></param>
        /// <returns></returns>
        public override IList<EvalRateView> GetEvaledEvalItems(DateTime begin, DateTime end, string schoolMark, int groupType, int groupID)
        {
            //PROC_GET_EVALITEMS_INGROUP
            String str = ConnectionString.Replace("GlobalUsers", schoolMark);
            using (SqlConnection conn = new SqlConnection(ConnectionString))
            {
                conn.Open();
                SqlCommand cmd = conn.CreateCommand();

                cmd.CommandText = "PROC_GET_EVALITEMS_INGROUP";
                cmd.CommandType = CommandType.StoredProcedure;

                SqlParameter schoolMarkParam = new SqlParameter("@schoolMark", SqlDbType.NVarChar);
                schoolMarkParam.Value = schoolMark;
                cmd.Parameters.Add(schoolMarkParam);

                SqlParameter startDatePara = new SqlParameter("@beginDate", SqlDbType.DateTime);
                startDatePara.Value = begin;
                cmd.Parameters.Add(startDatePara);

                SqlParameter endDatePara = new SqlParameter("@endDate", SqlDbType.DateTime);
                endDatePara.Value = end;
                cmd.Parameters.Add(endDatePara);

                SqlParameter groupTypeParam = new SqlParameter("@groupType", SqlDbType.Int);
                groupTypeParam.Value = groupType;
                cmd.Parameters.Add(groupTypeParam);

                SqlParameter groupIdParam = new SqlParameter("@groupID", SqlDbType.Int);
                groupIdParam.Value = groupID;
                cmd.Parameters.Add(groupIdParam);

                SqlDataReader dr = cmd.ExecuteReader();
                IList<EvalRateView> result = GetEvaledItems(dr);
                dr.Close();
                conn.Dispose();

                return result;
            }
        }

        /// <summary>
        /// 个人单项报表
        /// </summary>
        /// <param name="schoolMark"></param>
        /// <param name="begin"></param>
        /// <param name="end"></param>
        /// <param name="evalItemId"></param>
        /// <param name="teacherId"></param>
        /// <returns></returns>
        public override IList<PersonSingleReportView> GetPersonSingleReport(string schoolMark, DateTime begin, DateTime end, int evalItemId, int teacherId)
        {
            IList<PersonSingleReportView> result = new List<PersonSingleReportView>();
            //Hashtable ht = new Hashtable();
            //ht.Add("TableName", "TEMP_PERSON_SINGLE_REPORT");
            //ht.Add("SchoolMark", schoolMark);
            //InsertCustomer("EvalSheets.CreateTempTable", ht);
            String str = ConnectionString.Replace("GlobalUsers", schoolMark);
            using (SqlConnection conn = new SqlConnection(ConnectionString))
            {
                conn.Open();
                SqlCommand cmd = conn.CreateCommand();

                //cmd.CommandText = "PROC_CREATETEMPTABLE";
                //cmd.CommandType = CommandType.StoredProcedure;

                //SqlParameter tableParam = new SqlParameter("p_tableName", SqlDbType.NVarChar);
                //tableParam.Value = "TEMP_PERSON_SINGLE_REPORT";
                //cmd.Parameters.Add(tableParam);

                //SqlParameter schoolMarkPara = new SqlParameter("p_schoolMark", SqlDbType.NVarChar);
                //schoolMarkPara.Value = schoolMark;
                //cmd.Parameters.Add(schoolMarkPara);

                //cmd.ExecuteNonQuery();

                cmd = conn.CreateCommand();

                cmd.CommandText = "PROC_REPORT_PERSON_SINGLE";
                cmd.CommandType = CommandType.StoredProcedure;


                SqlParameter schoolMarkPara = new SqlParameter("@schoolMark", SqlDbType.NVarChar);
                schoolMarkPara.Value = schoolMark;
                cmd.Parameters.Add(schoolMarkPara);

                SqlParameter teachIDPara = new SqlParameter("@teacherId", SqlDbType.Int);
                teachIDPara.Value = teacherId;
                cmd.Parameters.Add(teachIDPara);

                SqlParameter evalItemIdPara = new SqlParameter("@evalItemId", SqlDbType.Int);
                evalItemIdPara.Value = evalItemId;
                cmd.Parameters.Add(evalItemIdPara);

                SqlParameter startDatePara = new SqlParameter("@beginDate", SqlDbType.DateTime);
                startDatePara.Value = begin;
                cmd.Parameters.Add(startDatePara);

                SqlParameter endDatePara = new SqlParameter("@endDate", SqlDbType.DateTime);
                endDatePara.Value = end;
                cmd.Parameters.Add(endDatePara);

                SqlDataReader dr = cmd.ExecuteReader();
                result = GetPersonSingleDate(dr);
                dr.Close();

                conn.Dispose();

            }
            return result;
        }

        /// <summary>
        /// 个人汇总报表
        /// </summary>
        /// <param name="schoolMark"></param>
        /// <param name="begin"></param>
        /// <param name="end"></param>
        /// <param name="teacherId"></param>
        /// <returns></returns>
        public override IList<PersonSummaryReportView> GetPersonSummaryReport(string schoolMark, DateTime begin, DateTime end, int teacherId)
        {
            IList<PersonSummaryReportView> result = new List<PersonSummaryReportView>();
            String str = ConnectionString.Replace("GlobalUsers", schoolMark);
            using (SqlConnection conn = new SqlConnection(ConnectionString))
            {
                conn.Open();
                SqlCommand cmd = conn.CreateCommand();

                //cmd.CommandText = schoolMark + ".PROC_CREATETEMPTABLE";
                //cmd.CommandType = CommandType.StoredProcedure;

                //SqlParameter tableParam = new SqlParameter("p_tableName", SqlDbType.NVarChar);
                //tableParam.Value = "TEMP_PERSON_SUMMARY_REPORT";
                //cmd.Parameters.Add(tableParam);

                //cmd.ExecuteNonQuery();

                //cmd = conn.CreateCommand();

                cmd.CommandText = "PROC_REPORT_PERSON_SUMMARY";
                cmd.CommandType = CommandType.StoredProcedure;

                SqlParameter schoolMarkParam = new SqlParameter("@schoolMark", SqlDbType.NVarChar);
                schoolMarkParam.Value = schoolMark;
                cmd.Parameters.Add(schoolMarkParam);

                SqlParameter teachIDPara = new SqlParameter("@teacherId", SqlDbType.Int);
                teachIDPara.Value = teacherId;
                cmd.Parameters.Add(teachIDPara);

                SqlParameter startDatePara = new SqlParameter("@beginDate", SqlDbType.DateTime);
                startDatePara.Value = begin;
                cmd.Parameters.Add(startDatePara);

                SqlParameter endDatePara = new SqlParameter("@endDate", SqlDbType.DateTime);
                endDatePara.Value = end;
                cmd.Parameters.Add(endDatePara);

                SqlDataReader dr = cmd.ExecuteReader();
                result = GetPersonSummaryDate(dr);
                dr.Close();
                conn.Dispose();

            }
            return result;
        }

        /// <summary>
        /// 单项汇总报表
        /// </summary>
        /// <param name="schoolMark"></param>
        /// <param name="begin"></param>
        /// <param name="end"></param>
        /// <param name="evalItemId"></param>
        /// <param name="groupType"></param>
        /// <param name="groupID"></param>
        /// <returns></returns>
        public override IList<SingleSummaryReportView> GetSingleSummaryReport(string schoolMark, DateTime begin, DateTime end, int evalItemId, int groupType, int groupID)
        {
            //TEMP_PERSON_SINGLE_REPORT
            String str = ConnectionString.Replace("GlobalUsers", schoolMark);
            using (SqlConnection conn = new SqlConnection(ConnectionString))
            {
                conn.Open();
                SqlCommand cmd = conn.CreateCommand();

                //cmd.CommandText = schoolMark + ".PROC_CREATETEMPTABLE";
                //cmd.CommandType = CommandType.StoredProcedure;

                //SqlParameter tableParam = new SqlParameter("p_tableName", SqlDbType.NVarChar);
                //tableParam.Value = "TEMP_PERSON_SINGLE_REPORT";
                //cmd.Parameters.Add(tableParam);

                //cmd.ExecuteNonQuery();

                //cmd = conn.CreateCommand();

                cmd.CommandText = "PROC_REPORT_SINGLE_SUMMARY";
                cmd.CommandType = CommandType.StoredProcedure;

                SqlParameter schoolMarkParam = new SqlParameter("@schoolMark", SqlDbType.NVarChar);
                schoolMarkParam.Value = schoolMark;
                cmd.Parameters.Add(schoolMarkParam);

                SqlParameter startDatePara = new SqlParameter("@beginDate", SqlDbType.DateTime);
                startDatePara.Value = begin;
                cmd.Parameters.Add(startDatePara);

                SqlParameter endDatePara = new SqlParameter("@endDate", SqlDbType.DateTime);
                endDatePara.Value = end;
                cmd.Parameters.Add(endDatePara);

                SqlParameter evalItemIdPara = new SqlParameter("@evalItemId", SqlDbType.Int);
                evalItemIdPara.Value = evalItemId;
                cmd.Parameters.Add(evalItemIdPara);

                SqlParameter groupTypeParam = new SqlParameter("@groupType", SqlDbType.Int);
                groupTypeParam.Value = groupType;
                cmd.Parameters.Add(groupTypeParam);

                SqlParameter groupIdParam = new SqlParameter("@groupID", SqlDbType.Int);
                groupIdParam.Value = groupID;
                cmd.Parameters.Add(groupIdParam);

                SqlDataReader dr = cmd.ExecuteReader();
                IList<SingleSummaryReportView> result = GetSingleSummaryDate(dr);
                dr.Close();
                conn.Dispose();

                return result;
            }
        }

        /// <summary>
        /// 根据学校标识获取某个学校的教师评分汇总
        /// </summary>
        /// <param name="schoolMark"></param>
        /// <param name="begin"></param>
        /// <param name="end"></param>
        /// <returns></returns>
        public override IList<ReportCollectView> GetReportCollectView(string schoolMark, DateTime begin, DateTime end)
        {
            //TEMP_REPORT_REPORTSUMM
            String str = ConnectionString.Replace("GlobalUsers", schoolMark);
            using (SqlConnection conn = new SqlConnection(ConnectionString))
            {
                conn.Open();
                SqlCommand cmd = conn.CreateCommand();

                cmd.CommandText = "PROC_REPORT_REPORTSUMM";
                cmd.CommandType = CommandType.StoredProcedure;

                SqlParameter schoolMarkParam = new SqlParameter("@schoolMark", SqlDbType.NVarChar);
                schoolMarkParam.Value = schoolMark;
                cmd.Parameters.Add(schoolMarkParam);

                SqlParameter startDatePara = new SqlParameter("@beginDate", SqlDbType.DateTime);
                startDatePara.Value = begin;
                cmd.Parameters.Add(startDatePara);

                SqlParameter endDatePara = new SqlParameter("@endDate", SqlDbType.DateTime);
                endDatePara.Value = end;
                cmd.Parameters.Add(endDatePara);

                SqlDataReader dr = cmd.ExecuteReader();
                //dr.
                IList<ReportCollectView> result = GetReportCollect(dr);
                dr.Close();
                conn.Dispose();

                return result;
            }

            return null;
        }
        /// <summary>
        /// GetEvaledItems
        /// </summary>
        private IList<EvalRateView> GetEvaledItems(SqlDataReader dr)
        {
            if (dr == null)
                return null;
            IList<EvalRateView> res = new List<EvalRateView>();

            while (dr.Read())
            {
                try
                {
                    EvalRateView view = new EvalRateView();

                    view.Rid = dr.GetInt32(0);
                    view.Eiid = dr.GetInt32(1);
                    view.Rate = dr.GetInt32(2);
                    view.EiName = dr.GetString(3);
                    res.Add(view);
                }
                catch (Exception)
                {
                    continue;
                }
            }
            return res;

        }

        /// <summary>
        /// GetReportCollect
        /// </summary>
        /// <param name="dr"></param>
        /// <returns></returns>
        private IList<ReportCollectView> GetReportCollect(SqlDataReader dr)
        {
            if (dr == null)
                return null;
            IList<ReportCollectView> res = new List<ReportCollectView>();

            while (dr.Read())
            {
                try
                {
                    ReportCollectView view = new ReportCollectView();

                    view.RID = dr.GetInt32(0);
                    view.TeachCode = dr.GetString(1);
                    view.TeachName = dr.GetString(2);
                    view.Score = dr[3] == DBNull.Value ? 0 : Convert.ToDouble(dr[3]);
                    view.ScoreTotal = dr[4] == DBNull.Value ? 0 : Convert.ToDouble(dr[4]);
                    view.ScorePrecentum = dr[5] == DBNull.Value ? 0 : Convert.ToDouble(dr[5]);
                    res.Add(view);
                }
                catch (Exception)
                {
                    continue;
                }
            }
            return res;

        }

        /// <summary>
        /// GetSingleSummaryDate
        /// </summary>
        /// <param name="dr"></param>
        /// <returns></returns>
        private IList<SingleSummaryReportView> GetSingleSummaryDate(SqlDataReader dr)
        {
            if (dr == null)
                return null;
            IList<SingleSummaryReportView> res = new List<SingleSummaryReportView>();

            while (dr.Read())
            {
                SingleSummaryReportView view = new SingleSummaryReportView();

                view.Rid = dr.GetInt32(0);
                view.Name = dr.GetString(1);
                view.Code = dr.GetString(2);
                view.Score = dr[3] == DBNull.Value ? 0 : Convert.ToDouble(dr[3]);
                view.Max = dr[4] == DBNull.Value ? 0 : Convert.ToDouble(dr[4]);
                view.Appraisals = dr.GetString(5);
                res.Add(view);
            }
            return res;
        }

        /// <summary>
        /// GetPersonSummaryDate
        /// </summary>
        /// <param name="dr"></param>
        /// <returns></returns>
        private IList<PersonSummaryReportView> GetPersonSummaryDate(SqlDataReader dr)
        {
            if (dr == null)
                return null;
            IList<PersonSummaryReportView> res = new List<PersonSummaryReportView>();

            while (dr.Read())
            {
                PersonSummaryReportView view = new PersonSummaryReportView();

                view.Rid = dr.GetInt32(0);
                view.EvalItemName = dr.GetString(1);
                view.Score = dr[2] == DBNull.Value ? 0 : Convert.ToDouble(dr[2]);
                view.Max = dr[3] == DBNull.Value ? 0 : Convert.ToDouble(dr[3]);
                view.Rate = dr[4] == DBNull.Value ? 0 : Convert.ToDouble(dr[4]);
                view.Apprisals = dr.GetString(5);
                res.Add(view);
            }
            return res;
        }

        /// <summary>
        /// GetPersonSingleDate
        /// </summary>
        /// <param name="dr"></param>
        /// <returns></returns>
        private IList<PersonSingleReportView> GetPersonSingleDate(SqlDataReader dr)
        {
            if (dr == null)
                return null;
            IList<PersonSingleReportView> res = new List<PersonSingleReportView>();

            while (dr.Read())
            {
                PersonSingleReportView view = new PersonSingleReportView();

                view.Rid = dr.GetInt32(0);
                view.SheetName = dr.GetString(1);
                view.EvalDate = dr.GetDateTime(2);
                view.Score = dr[3] == DBNull.Value ? 0 : Convert.ToDouble(dr[3]);
                view.TemplateName = dr.GetString(5);
                view.Apprisals = dr.GetString(6);
                res.Add(view);
            }
            return res;
        }
    }
}
